package com.vinxin.app.service

import cn.hutool.log.Log
import cn.hutool.log.LogFactory
import com.alibaba.fastjson2.JSONPath
import com.vinxin.app.boss.feign.BossFeign
import com.vinxin.app.model.SelectorVo
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.http.HttpHeaders
import org.springframework.stereotype.Service

@Service
class StationService {
    private val log: Log = LogFactory.get()

    @Autowired
    private lateinit var bossFeign: BossFeign

    fun getList(headers: HttpHeaders): List<SelectorVo> {
        val result = bossFeign.getStationList(headers)
        val size: Int = JSONPath.extract(result, "$.onlineJobList.size()")?.toString()?.toIntOrNull() ?: 0

        return (0 until size).mapIndexed { index, _ ->
            val jobName = JSONPath.extract(result, "$.onlineJobList[$index].jobName") as String
            val locationName = JSONPath.extract(result, "$.onlineJobList[$index].locationName") as String
            val salaryDesc = JSONPath.extract(result, "$.onlineJobList[$index].salaryDesc") as String
            val encryptId = JSONPath.extract(result, "$.onlineJobList[$index].encryptId") as String

            SelectorVo("$jobName $locationName $salaryDesc".replace(" ", "_"), encryptId)
        }
    }
}